package com.csgc.camera.biz.other.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle

import com.csgc.camera.base.BaseBindingActivity
import com.csgc.camera.constants.MaskConfig

import com.csgc.camera.events.MaskUpdateContent
import com.csgc.camera.storage.MaskPreference
import com.csgc.camera.util.clickWithTrigger
import com.cysd.spsyxj.R
import com.cysd.spsyxj.databinding.ActivityUpdateMaskContentBinding

import com.drake.channel.sendEvent
import com.gyf.immersionbar.ktx.immersionBar
import com.hjq.toast.ToastUtils

class UpdateMaskInfoContentActivity:BaseBindingActivity<ActivityUpdateMaskContentBinding>(ActivityUpdateMaskContentBinding::inflate) {

    companion object{
        fun launch(context: Context,title:String){
            val intent = Intent(context,UpdateMaskInfoContentActivity::class.java)
            intent.putExtra("title",title)
            context.startActivity(intent)
        }
    }
    val title:String by lazy {
        intent.getStringExtra("title")?:""
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        immersionBar {
            //界面在状态栏底部true   界面在状态栏下面沉浸式盖着界面false
            fitsSystemWindows(true)
            //白色状态栏，黑色字体
            statusBarColor(R.color.white)
            statusBarDarkFont(true)
        }

        binding.tvContentTitle.text = title
        binding.etContent.hint = "请输入${title}内容"
        binding.ivBack.clickWithTrigger { finish() }
        binding.stvSave.clickWithTrigger {
            val content = binding.etContent.text.toString().trim()
            if(content.isEmpty()){
                ToastUtils.show("内容不能为空")
                return@clickWithTrigger
            }

            val maskType = MaskPreference.instance.getMaskType()
            val maskId = MaskPreference.instance.getMaskId()

            MaskConfig.maskMap[maskType]?.forEach {
                if (it.title == title && !it.isCustom){
                    it.content = content
                }
            }
            sendEvent(MaskUpdateContent(title,content))

            finish()

        }
    }



}